package spring.test4;

import com.blackhorse.dao.AccountDao;
import com.blackhorse.domain.Account;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 基于JdbcTemplate的dao测试
 */
public class Demo2_JdbcTemplateDao {
    private ApplicationContext applicationContext;
    private AccountDao dao;

    @Before
    public void init() {
        String xmlPath = "jdbcTemplate/beans.xml";
        applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        dao = (AccountDao) applicationContext.getBean("accountDaoWithJdbcTemplate");
    }

    @Test
    public void testFindAccountById() {
        Account account = dao.findAccountById(2);
        System.out.println(account);
    }


    @Test
    public void testFindAccountByName() {
        Account account = dao.findAccountByName("张三三");
        System.out.println(account);
    }

    @Test
    public void testUpdateAccount() {
        Account account = new Account();
        account.setId(5);
        account.setName("张三三");
        account.setMoney(2222.2f);
        dao.updateAccount(account);
    }


}
